<template>
	<view class="archives">
		
		<view class="archives_list" v-if="auditShow">
			<view class="archives_list_item flex_row_start_center" v-for="(item,index) in archivesList" :key="index">
				<view @click="changeIndex(item,index)">
					<view v-if="currentIndex==index"  class="cuIcon-roundcheckfill archives_list_item_l"></view>
					<view v-else class="cuIcon-round archives_list_item_l"></view>
				</view>
				<view class="archives_list_item_r flex_row_between_center">
					<view class="archives_list_item_r_info">
						<view>{{item.masterName}}</view>
						<view>
							<text style="margin-right: 10rpx;">{{item.masterBirthday}}</text>
							<text>{{item.masterAddress}}</text>
						</view>
					</view>
					<view class="archives_list_item_r_edit" @click="editChange(item)">
						<text class="cuIcon-post"></text>
						<text>编辑</text>
					</view>
				</view>
			</view>
		</view>
		
		
		
		
		<!-- <view class="archives_button flex_row_between_center ">
			<view class="archives_button_l" @click="addArchives">
				<text class="cuIcon-add text-pink lg"></text>
				<text>新增</text>
			</view>		
			<view class="archives_button_r"  @click="confirmChange">确认选择</view>		
		</view> -->
		<view class="archives_button flex_row_center_center"  @click="confirmChange">确认选择</view>
		<loginPop ref="loginPop" ></loginPop>
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex'
	export default{
		data(){
			return{
				archivesList:[],
				currentIndex:null,
		        currentInfo:'',
				 auditShow:false,
			}
		},
		onLoad(){},
		onShow(){
			this.getAudit()
			if(!this.hasLogin){
				this.archivesList.push(uni.getStorageSync('exampleInfo'))
				this.currentIndex=0
			}else{
				this.getArchivesInfo()
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'userCenterData'])
		},
		methods:{
			//获取微信审核开关
			getAudit(){
			    let param = {};
				param.url='v3/system/front/configuration/1'
				this.$request(param).then(res=>{
					console.log(res);
					this.auditShow=res.data.auditSwitch
					
				})
			},
			getArchivesInfo(){
				let param = {};
				param.url='v3/member/front/master/list'
				this.$request(param).then(res =>{
					console.log(res);
					if(res.state==200){
						this.archivesList=res.data
						if(res.data &&  res.data.length == 0){
							this.archivesList.push(uni.getStorageSync('exampleInfo'))
						}
						this.currentInfo=this.filterList(this.archivesList)[0]
					}
				})
			},
			filterList(list){
				let _this=this
				var newList = list.filter(function (item,index) {
					// console.log(item.isSelect);
					// console.log('index',index);
					if (item.isSelect == 'true') {
						// console.log('1');
						_this.currentIndex=index
						
						return item;
					}
				})
				return newList
			},
			changeIndex(item,index){
				this.currentIndex=index
				 let info=JSON.parse(JSON.stringify(item))
				 info.isSelect=true
				 this.currentInfo=info
			     
			},
			confirmChange(){
				if(this.currentIndex==null){
					this.$modal.msg('请选择!')
					return false
				}
				if(!this.hasLogin){
					this.$tab.navigateBack()
				}else{
					let param={}
					param.url='v3/member/front/master/update'
					param.data=this.currentInfo
					param.method="POST"
					param.header={
						'Content-Type': 'application/json'
					},
					console.log(param);
					this.$request(param).then(res=>{
						console.log(res);
						if(res.state==200){
						  // this.$modal.msg('修改成功!')
					      setTimeout(()=>{
							  this.$tab.navigateBack()
						  },1000)					
						}else{
							this.$modal.msg(res.msg)
						}
					})
				}
				
			},
			addArchives(){
				if(!this.hasLogin){
					this.$refs.loginPop.openLogin()
				}else{
					this.$tab.navigateTo('/pages/index/addArchives')
				}
			},
			editChange(item){
				const url='/pages/index/addArchives'
				// 要传递的对象参数
				const obj =item
				// 将对象参数转为JSON字符串，并使用encodeURIComponent编码
				const params = encodeURIComponent(JSON.stringify(obj));
				
				// 跳转页面并传递对象参数
				uni.navigateTo({
				   url: `${url}?params=${params}`
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #ffffff;
	}
	.archives{
		padding-bottom: 125rpx;
	}
	.archives_button{
		position: fixed;
		bottom: 0;
		width: 550rpx;
		// height: 0rpx;
		background-color: #fff;
		padding: 20rpx 32rpx;
		margin: 0 100rpx 20rpx 100rpx ;
		display: flex;
		font-size: 24rpx;
		border-radius: 50rpx;
		font-weight: bold;
		background-image: linear-gradient(to right ,#a3fbff,#82e8ff);
		
	}
	
	.archives_list{
		
		.archives_list_item{
			background-color: #fff;
			padding: 20rpx 32rpx;
			border-bottom: 2rpx solid #cecece;
			
			.archives_list_item_l{
				width: 50rpx;
				font-size: 32rpx;
				margin-right: 14rpx;
			}
			
			.archives_list_item_r{
				width: 622rpx;
				
				.archives_list_item_r_info{
					font-size: 30rpx;
					& view:last-child{
						font-size: 24rpx;
						color: #939393;
						margin-top: 10rpx;
					}
				}
				
				.archives_list_item_r_edit{
					background-color: #b0feff;
					color: #53e0ff;
					font-size: 20rpx;
					padding: 6rpx 10rpx;
					border-radius: 6rpx;
					margin-left: 4rpx;
				}
			}
		}
	}
</style>